package model

import (
	"gorm.io/gorm"
	"user-server/basic/config"
)

type User struct {
	gorm.Model
	Username string `gorm:"type:varchar(20)" json:"username" binding:"required"`
	Password string `gorm:"type:varchar(32)" json:"password" binding:"required"`
	Mobile   string `gorm:"type:char(11)" json:"mobile" binding:"required"`
}

type Membership struct {
	gorm.Model
	UserId     int    `gorm:"type:int" json:"user_id" binding:"required"`
	Membership string `gorm:"type:varchar(20)" json:"membership" binding:"required"`
	Duration   string `gorm:"type:varchar(20)" json:"duration" binding:"required"`
}

func (m *Membership) CreateMembership() error {
	return config.DB.Create(&m).Error
}

type Order struct {
	gorm.Model
	UserId       int     `gorm:"type:int" json:"user_id" binding:"required"`
	MembershipId int     `gorm:"type:int" json:"membership_id" binding:"required"`
	Price        float64 `gorm:"type:decimal(10,2)" json:"price" binding:"required"`
}

type Pay struct {
	gorm.Model
	UserId       int     `gorm:"type:int" json:"user_id" binding:"required"`
	MembershipId int     `gorm:"type:int" json:"membership_id" binding:"required"`
	TotalAmount  float64 `gorm:"type:decimal(10,2)" json:"total_amount" binding:"required"`
	Status       int     `gorm:"type:tinyint" json:"status" binding:"required"`
}
